<?php
/*
Plugin Name: Sina blog content filter 
Plugin URI: http://www.xys-reader.org/blogs
Description: To modify the blog from sina blog. The image source url will be changed. The <PRE> tag will be removed. 
Version: 0.1 
Author: Liu Xuefeng
Author URI: http://www.xys-reader.org/blogs/sys_admin
*/

add_filter('the_content', 'sinablog_filter');
function sinablog_filter($content) {
	global $blog;

// $content = preg_replace('|<blockquote([^>]*)><p>|i', "<blockquote$1>",$content);//PEAK
// $content = preg_replace('|</p><blockquote>|i', "<blockquote>",$content);//PEAK

  preg_match("/([^\/]+)$/",get_bloginfo("home"),$blog_home_matched);


//  $content = preg_replace('/SRC="http:\/\/([0-9a-z]{1,5})\.album\.sina\.com\.cn\/([^"]+)\"/i',"src=\"http://www.de-sci.org/blogs/dev/get.php?img=$1.album.sina.com.cn/$2&user=".$blog."\" ", $content); #PEAK ADD
 // $content = preg_replace('/src="http:\/\/blog\.sina\.com\.cn\/pic\/([^"]{10,25})\"/i',"src=\"http://www.de-sci.org/blogs/dev/get.php?img=blog.sina.com.cn/pic/$1&user=".$blog."\" ", $content); #PEAK ADD | To deal with sina blog

  //$content = preg_replace('/src="http:\/\/(.*)\.sina\.com\.cn\/(.*)"/i',"src=\"http://www.de-sci.org/blogs/dev/get.php?img=$1.sina.com.cn/$2&user=".$blog."\" ", $content); #PEAK ADD | To deal with sina blog

  //$content = preg_replace('/src="http:\/\/(.*)\.sohu\.com([\.cn]*)\/images\/(.*).jpg"/i',"src=\"http://www.de-sci.org/blogs/dev/get_img.php?img=http://$1.sohu.com$2/images/$3.jpg&user=".$blog_home_matched[1]."\" alt=\"Image from sohu blog.\"", $content); #PEAK ADD | To deal with images from sohu. 


  $content = preg_replace('/^(\s*)\n/'," ", $content); #PEAK ADD| To deal with sina blog
  if(preg_match('/^(\s*)\<pre\>/',$content) ){ #PEAK ADD| To deal with sina blog
        $content = preg_replace('/^(\s*)\<pre\>/'," ", $content); #PEAK ADD To deal with sina blog
        $content = preg_replace('/\n/',"<br> ", $content); #PEAK ADD|To deal with sina blog
        $content = preg_replace('/<pre>(\s*)$/'," ", $content); #PEAK ADD|To deal with sina blog
  }
        $content = preg_replace('/\;<br \/>/',";", $content); #PEAK ADD|To deal with sina blog
        $content = preg_replace('/\-\-<br \/>/',"--", $content); #PEAK ADD|To deal with sina blog

/*
  $content = preg_replace_callback( '/<script(.*)script>/i',
                create_function(
                    '$matches',
                    'return "<!--    ".preg_replace("/<br \/>/","",$mathes[1])."-->";'
                ),
                $content );
*/


  $content = preg_replace('/<div([^\/>]*)\/>/',"", $content); #PEAK ADD|To deal with sina blog

/*
  $ad='
<hr size=1>
<div style="margin:9px auto 5px 10px;height:40px;">
&nbsp;
&nbsp;
本站推荐使用Firefox浏览器
(<a href="http://www.xys-reader.org/blogs/sys_admin/2007/12/09/firefox/"> 为什么？</a>)
<script type="text/javascript"><!--
google_ad_client = "pub-3862237077930400";
//110x32，创建于 08-1-17
google_ad_slot = "8582186754";
google_ad_width = 110;
google_ad_height = 32;
google_cpa_choice = ""; // on file
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
';
*/

/*
	get_currentuserinfo();

	$myblogs = get_userblogs();
	$sys_admin_user=0;
	if ($myblogs) {
		foreach ($myblogs as $b)
			if($b->id ==2) $sys_admin_user=1;
	}	
	if($sys_admin_user ){


    global $id, $post;
    $url="http://www.xys-reader.org/blogs/".$post->blogname."/?p=".$post->ID;
    $special_edit="<div align=\"right\" ><form action=\"http://www.xys-reader.org/xys/p_add_product_to_cat_by_link.php\" method=\"post\" target=\"_new\">";

    $special_edit.="<input type=\"hidden\" name=\"parent_cat_id\" value=\"27353\">\n";
   $special_edit.="<input type=\"hidden\" name=\"arc_title\" value=\"".$post->post_title."\">\n";
    $special_edit.="<input type=\"hidden\" name=\"arc_link\" value=\"$url\">\n";
    $special_edit.="<input type=\"hidden\" name=\"arc_author\" value=\"".$post->author_nickname."\">\n";
    $special_edit.="<input type=\"hidden\" name=\"arc_date\" value=\"".$post->post_modified."\">\n";
    $special_edit.="<input type=\"hidden\" name=\"arc_ID\" value=\"".$post->ID."\">\n";
    $special_edit.="<input type=\"submit\" name=\"arc_submit\" value=\"Add to HOT Album\">";
   $special_edit.="</form></div>";
   //$special_edit.=print_r($post,1);

  }

*/


  //if(!is_home()) $content=$special_edit.$content.$special_edit;
  return $content;

}

?>
